﻿using AutoMapper;
using MediatR;
using S.BreedingHistory.Domain.Model;
using S.BreedingHistory.Infrastructure.Interface;
using S.BreedingHistory.Read.Api.Application.Command;
using S.BreedingHistory.Read.Api.Dto;

namespace S.BreedingHistory.Read.Api.Application.CommandHandler
{
    public class BreedingHistoryGetByIdCommandHandler : IRequestHandler<BreedingHistoryGetByIdCommand, BreedingHistoryListDto>
    {
        private readonly IBreedingHistoryRepository breedingHistoryRepository;
        private readonly IMapper mapper;

        public BreedingHistoryGetByIdCommandHandler(IBreedingHistoryRepository breedingHistoryRepository,IMapper mapper)
        {
            this.breedingHistoryRepository = breedingHistoryRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 种母历史记录的反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<BreedingHistoryListDto> Handle(BreedingHistoryGetByIdCommand request, CancellationToken cancellationToken)
        {
            BreedingHistoryModel breedingHistoryModel=await  breedingHistoryRepository.GetBreedingHistoryById(request.EarTag);
            BreedingHistoryListDto breedingHistoryListDto = mapper.Map<BreedingHistoryListDto>(breedingHistoryModel);
            return breedingHistoryListDto;
        }
    }
}
